<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun(){
				//1.创建XMLHttpRequest对象
				let xhr=new XMLHttpRequest()  //**  
				//2.创建请求
				xhr.open("GET","data.txt",true)//true表示异步请求
				//3.发送请求
				xhr.send()  //**
				//4.接收,解析,显示数据
				xhr.onreadystatechange=function(){
					if(xhr.readyState==4&&xhr.status==200){
						let data=xhr.responseText
						document.querySelector("span").innerHTML=data
					}
				}
				
			}
		</script>
	</head>
	<body>
		请求到的数据是：<span></span><br>	
		<button type="button" onclick="fun()">请求</button>
	</body>
</html>
